/**
 * Code is from pre-alpha
 * Needs to be updated for Alpha
 * */

using UnityEngine;
using System.Collections;

[System.Serializable]
public class DisplayMessage : MonoBehaviour {
	
	public bool disableControl = true;
	
	public int chapter = 0;
	
	public CharacterMotor characterMotor = null;
	
	public bool isTrigger = false;
	
	public const int CHAPTER_1_TRAINSTATION = 0;
	public static string CHAPTER_1_MESSAGE = 
		"May 17th 2012\n" +
		"You arrive at the train stration, it's pitch black.\n" +
		"'I must have fallen asleep on the train, what a long train ride.'\n" +
		"You look around you, the only lights you can see, are those at the platform.\n" +
		"It seems the town is not powered by electricity, only the station.\n" +
		"\n" +
		"I need to meet up with my friend at 104A" +
		"\n" +
		"HINT: Use 'F' to turn on your flashlight\n" +
		"HINT: Press 'R' to close this message.\n" +
		"HINT: Press 'Z' to zoom";
	
	
	private bool hideMessage = false;
	
	private string message = null;
	
	private bool triggered = false;
	
	private bool messageShown = false;
	
	// Use this for initialization
	void Start () {
		switch (chapter) {
			case CHAPTER_1_TRAINSTATION : 
				message = CHAPTER_1_MESSAGE;
				break;
			default:
				message = null;
				break;
		}	
		
		if (disableControl) {
			characterMotor.canControl = false;
		}
	}
	
	// Update is called once per frame
	void Update () {
		if (!hideMessage && messageShown) {
			hideMessage = Input.GetKey("r");	
		}
	}
	
	void OnTriggerEnter(Collider collision) {
		if (collision.tag == "Player") {
			triggered = true;          
        }
	}
	
	void OnGUI() {
		if (!hideMessage && message != null) {
			if (isTrigger && triggered) {
				displayGUIMessage();
			} else if (!isTrigger) {
				displayGUIMessage();	
			}
		} else {
			characterMotor.canControl = true;
		}
	}
	
	void displayGUIMessage() {
		GUI.Box(new Rect(0,0, 500, 200), message);
		messageShown = true;
	}
}
